<template>
    <el-dialog
      title="选择位置"
      :visible.sync="dialogGroupVisible"
      :before-close="handleGroupClose"
      class="demo-ruleForm"
      custom-class="el-dialog-flex"
      :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-table
          :data="grouptableData"
          border
          highlight-current-row
          @current-change="handleSelectionChange"
          style="width: 100%;margin-top:10px;margin-bottom:10px"
          ref="groupTable"
          height="100%"
          >
          <el-table-column type="index" align="center" label="选择"></el-table-column>
          <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" prop="position" label="会议室位置"></el-table-column>
          <el-table-column min-width="100px" sortable :show-overflow-tooltip="true" prop="location" label="地理位置"></el-table-column>
        </el-table>
        
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleGroupSure(true)">
          确定
          <i class="el-icon-document-checked el-icon--right"></i>
        </el-button>
        <el-button @click="handleGroupSure(false)">
          取消
          <i class="el-icon-refresh-left"></i>
        </el-button>
      </span>
    </el-dialog>
</template>
<script>
import {
    Dialog,
    Table,
    TableColumn,
    Pagination,
    MessageBox,
    Message,
    Drawer
  } from 'element-ui';
  import {
        getPositionList, //列表数据
       
    } from '@/api/conference/Initialize.js'
export default {
    props: ['dialogGroupVisible'],
    components: {
      'el-dialog': Dialog, // 对话框
      'el-table': Table, // 表格
      'el-table-column': TableColumn, // 表格列
      'el-pagination': Pagination, // 分页
      'el-drawer': Drawer // 对话框
    },
    data(){
        return {
            grouptableData: [],
            checkDatas:[]
        }
    },
    created() {
        this.getTabTree()
        window.onresize = () => {
            this.$refs.groupTable.doLayout()
        }
    },
    methods:{
        getTabTree(){
            getPositionList({
                
            }).then(res => {
            if(res.data.code == 10000){
                this.grouptableData = res.data.data.records
                setTimeout(() => {
                    this.$refs.groupTable.doLayout() // 表格刷新以后，重绘表格宽度
                }, 0)
            }
            }).catch(res => {
            resolve([])
            })
        },
        // 获取所有数据
      distributionGroupEvent () {
        // let data = {
        //   page: this.currentUserPage,
        //   size: this.pageUserSize
        // }
        // data.type = 1
        // data.userName = this.textSearchUser
        // data.name = this.textSearchUser
        // this.axios.get('/user/list', {
        //   params: data
        // }).then(res => {
        //   this.grouptableData = res.data.data.records
        //   this.totalUser = res.data.data.total
        //   setTimeout(() => {
        //     this.$refs.groupTable.doLayout() // 表格刷新以后，重绘表格宽度
        //   }, 0)
        // })
      },
      // 复选框
      handleSelectionChange (val) {
        this.checkDatas = val
      },
      
      // 关闭弹框
      handleGroupClose () {
        this.$emit('dialogEmployeesData', false)
        this.$refs.groupTable.clearSelection()
      },
      // 点击取消弹框触发事件
      handleGroupCloseCheck () {
        this.handleGroupClose()
      },
      // 点击确认弹框触发事件
      handleGroupSure (result) {
          if (!result) {
            return this.handleGroupClose()
        }
		if(this.checkDatas.length < 1){//如果没有选择位置
			Message.warning("您还没有选择会议室位置哦")
					return
		}
        this.$emit('dialogEmployeesData', this.checkDatas)
        // this.allocationGroupData = this.allocationGroupData.concat(this.checkDatas)
        // let userIds = []
        // this.allocationGroupData.forEach(e => {
        //   userIds.push(e.userAccountId)
        // })
        // this.checkDatas.forEach(e => {
        //   if (userIds.indexOf(e.userAccountId) == -1) {
        //     e.userAccountId = e.userAccountId
        //     this.allocationGroupData.push(e)
        //   }
        // })
        this.handleGroupClose()
      },
    }
}
</script>